const fs = require('fs');
const XLSX = require('xlsx');

async function importXLSX(path) {
    return new Promise(function (resolve, reject) {
        try {
            fs.readFile(path, function (err, data) {
                if (err) {
                    reject(err.message || err);
                } else {
                    let wb = XLSX.read(data, {type: 'buffer'});
                    let ws = wb.Sheets[wb.SheetNames[0]];
                    resolve(XLSX.utils.sheet_to_json(ws, {blankrows: false}));
                }
            });
        } catch (e) {
            reject(e.message || e);
        }
    });
}

module.exports = importXLSX;